﻿using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Media;
using LiveCharts.Definitions.Points;
using LiveCharts.Definitions.Series;
using LiveCharts.Helpers;
using LiveCharts.SeriesAlgorithms;
using LiveCharts.Wpf;

namespace LiveCharts.Wpf
{
	public class GOhlcSeries : GearedSeries, ISeriesView, IFinancialSeriesView
	{
		public GOhlcSeries()
		{
			base.Model = new OhlcAlgorithm(this);
			this.method_2();
		}

		public GOhlcSeries(object configuration)
		{
			base.Model = new OhlcAlgorithm(this);
			base.Configuration = configuration;
			this.method_2();
		}

 
		internal ShapesStroke AltShapesStroke { get; set; }
 
		public double MaxColumnWidth
		{
			get
			{
				return (double)base.GetValue(GOhlcSeries.MaxColumnWidthProperty);
			}
			set
			{
				base.SetValue(GOhlcSeries.MaxColumnWidthProperty, value);
			}
		}
 
		public Brush IncreaseBrush
		{
			get
			{
				return (Brush)base.GetValue(GOhlcSeries.IncreaseBrushProperty);
			}
			set
			{
				base.SetValue(GOhlcSeries.IncreaseBrushProperty, value);
			}
		}
 
		public Brush DecreaseBrush
		{
			get
			{
				return (Brush)base.GetValue(GOhlcSeries.DecreaseBrushProperty);
			}
			set
			{
				base.SetValue(GOhlcSeries.DecreaseBrushProperty, value);
			}
		}

		public override void OnSeriesUpdateStart()
		{
			if (base.ShapesStroke == null)
			{
				base.ShapesStroke = new ShapesStroke();
			}
			if (this.AltShapesStroke == null)
			{
				this.AltShapesStroke = new ShapesStroke();
			}
			base.ShapesStroke.method_0(this.IncreaseBrush, this.IncreaseBrush, this);
			this.AltShapesStroke.method_0(this.DecreaseBrush, this.DecreaseBrush, this);
		}

		public override void Erase(bool removeFromView = true)
		{
			this.method_3(removeFromView);
		}

		public override IChartPointView GetPointView(ChartPoint point, string label)
		{
			Class8 @class = (Class8)point.View;
			if (@class == null)
			{
				Class8 class2 = new Class8();
				class2.IsNew = true;
				class2.method_1(new Class4());
				@class = class2;
			}
			else
			{
				@class.IsNew = false;
				point.SeriesView.Model.Chart.View.EnsureElementBelongsToCurrentDrawMargin(@class.DataLabel);
			}
			if (base.DataLabels && @class.DataLabel == null)
			{
				@class.DataLabel = (@class.DataLabel = base.UpdateLabelContent(new DataLabelViewModel
				{
					FormattedText = label,
					Point = point
				}, @class.DataLabel));
			}
			if (!base.DataLabels && @class.DataLabel != null)
			{
				base.Model.Chart.View.RemoveFromDrawMargin(@class.DataLabel);
				@class.DataLabel = null;
			}
			return @class;
		}

		private void method_2()
		{
			base.SetCurrentValue(Series.StrokeThicknessProperty, 1.0);
			base.SetCurrentValue(GOhlcSeries.MaxColumnWidthProperty, 35.0);
			base.SetCurrentValue(FrameworkElement.MaxWidthProperty, 25.0);
			base.SetCurrentValue(GOhlcSeries.IncreaseBrushProperty, new SolidColorBrush(Color.FromRgb(254, 178, 0)));
			base.SetCurrentValue(GOhlcSeries.DecreaseBrushProperty, new SolidColorBrush(Color.FromRgb(238, 83, 80)));
			Func<ChartPoint, string> value = c => $"O: {c.Open}, H: {c.High}, L: {c.Low} C: {c.Close}";
            base.SetValue(Series.LabelPointProperty, value);
			base.DefaultFillOpacity = 1.0;
			
		}

		private void method_3(bool bool_0)
		{
			base.ActualValues.GetPoints(this).ForEach(new Action<ChartPoint>(this.method_4));
			if (bool_0)
			{
				base.Model.Chart.View.RemoveFromDrawMargin(base.ShapesStroke.Path_0);
				base.Model.Chart.View.RemoveFromDrawMargin(this.AltShapesStroke.Path_0);
				base.Model.Chart.View.RemoveFromView(this);
			}
		}

		[CompilerGenerated]
		private void method_4(ChartPoint chartPoint_0)
		{
			if (chartPoint_0.View != null)
			{
				chartPoint_0.View.RemoveFromView(base.Model.Chart);
			}
		}

	 

		public static readonly DependencyProperty MaxColumnWidthProperty = DependencyProperty.Register("MaxColumnWidth", typeof(double), typeof(GOhlcSeries), new PropertyMetadata(0.0));

		public static readonly DependencyProperty IncreaseBrushProperty = DependencyProperty.Register("IncreaseBrush", typeof(Brush), typeof(GOhlcSeries), new PropertyMetadata(null));

		public static readonly DependencyProperty DecreaseBrushProperty = DependencyProperty.Register("DecreaseBrush", typeof(Brush), typeof(GOhlcSeries), new PropertyMetadata(null));
	}
}
